#
#    Copyright (C) 2016 Francisco Javier Parra <franparpe@openmailbox.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#

import numpy as np
from qtcam.core.parameters import SectionParameters


class StopSection(SectionParameters):
    """This represents the stopped section
    of a cam wich means that this section do not porduce movement

    """
    def __init__(self, StartAngle, EndAngle, Position,
                 AngularVelocity, precision=0.1):
        self.AngularVelocity = AngularVelocity
        self.StartAngle = StartAngle
        self.EndAngle = EndAngle
        self.HighestPosition = Position
        self.LowestPosition = 0  # irrelevant
        self.Precision = precision
        self.abcissaeValues = np.arange(self.StartAngle,
                                        self.EndAngle,
                                        self.Precision)
        self.beta = 1  # irrelevant in this case

    def ArrayPosition(self):
        """This returns an array with the position values
        
        """
        result = []
        for a in self.abcissaeValues:
            result.append(self.HighestPosition)

        return result

    def ArrayVelocity(self):
        """Returns the derivativ of the position, but
        because there was no movement, the derivative
        is all 0
        
        """
        result = []
        for a in self.abcissaeValues:
            result.append(0)
            
        return result

    def ArrayAcceleration(self):
        """Returns the derivative of the velocity,
        which is zero for any angle
        
        """
        return self.ArrayVelocity()

    def ArrayOverAcceleration(self):
        """Returns the derivative of the acceleration,
        which is zero for any angle
        
        """
        return self.ArrayVelocity()

    def CreateYaxisPosition(self,):  # eliminar para crear algo mejor
        """This method initializes two arrays atributes, the first is the
        angle and the second is the Position"""
        self.ordinatePosition = self.ArrayPosition()

    def CreateYaxisVelocity(self,):
        """This method creates the ordinate values for the Velocity"""
        self.ordinateVelocity = self.ArrayVelocity()

    def CreateYaxisAcceleration(self,):
        """This method creates the ordinate values for the Acceleration"""
        self.ordinateAcceleration = self.ArrayAcceleration()

    def CreateYaxisOverAcceleration(self,):
        """This method creates the ordinate values for the
        overacceleration"""
        self.ordinateOverAcceleration = self.ArrayOverAcceleration()
